package me.xiaoyan.java.chapter12;

import java.util.Scanner;

public class ShoppingSystem {
	int minNumber = 0;
	int maxNumber = 3;
	
	//登录菜单
	public void showLoginMenu()
	{
		System.out.println("1.登录");
		System.out.println("2.退出");
		System.out.print("请选择,输入数字:");
		
		//设置输入数字限制
		maxNumber = 3;
		minNumber = 0;
		int choice = getInputNumber();
		switch(choice)
		{
		case 1:
			showMainMenu();
			break;
		case 2:
			System.out.println("您已经退出系统");
			break;
		}
		
	}
	
	/**
	 * 显示主菜单
	 */
	public void showMainMenu()
	{
		System.out.println("1.客户管理");
		System.out.println("2.真情回馈");
		
		System.out.print("请选择，输入数字或者按0返回上一级菜单:");
		//设置输入数字限制
		minNumber = -1;
		maxNumber = 3;
		int choice = getInputNumber();
		switch (choice) {
		case 0:
			showLoginMenu();
			break;
		case 1:
			showCustMenu();//显示客户管理
			break;
		case 2:
			showRepay();//显示真情回馈
			break;
		}
	}
	
	/**
	 * 客户管理菜单
	 */
	public void showCustMenu()
	{
		System.out.println("1.显示所有客户信息");
		System.out.println("2.添加客户信息");
		System.out.println("3.修改客户信息");
		System.out.println("4.查询客户信息");
	}
	
	/**
	 * 真情回馈菜单
	 */
	public void showRepay()
	{
		System.out.println("1.幸运大抽奖");
		System.out.println("2.幸运抽奖");
		System.out.println("3.生日问候");
	}
	
	/**
	 * 获取输入数字
	 * @return
	 */
	public int getInputNumber()
	{
		Scanner input = new Scanner(System.in);
		int choice = 1;
		do{
			choice = input.nextInt();
			if(choice < maxNumber 
					&& choice > minNumber)
			{
				return choice;
			}
			System.out.print("输入错误，请重新输入:");
		}while(true);
	}
	
	public static void main(String[] args) {
		//创建购物系统对象
		ShoppingSystem system = new ShoppingSystem();
		//显示登陆菜单
		system.showLoginMenu();
	}
	
}
